﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraBars.Docking2010.Views;
using System.Reflection;
using DevExpress.XtraSplashScreen;
using System.Configuration;
using CP.Utility;
using CP.Controllers.GPM;
using System.Linq;
using DevExpress.XtraNavBar;
using GPM;

namespace LF3Proj
{
    public partial class FrmMain : DevExpress.XtraEditors.XtraForm
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        public void DisplayMessage()
        { 
            
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            this.Text = AppSetter.SoftName;
            splashScreenManager1.ShowWaitForm();

            LoadMonitor();
            splashScreenManager1.CloseWaitForm();
        }

        private void ExtractForm(string formName, string nameSpace)
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == formName)
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }

            Assembly currentAssembly = Assembly.Load(nameSpace);
            Form xtraform = (Form)currentAssembly.CreateInstance(nameSpace + "." + formName);
            if (null != xtraform)
            {
                xtraform.MdiParent = this;
                xtraform.Show();
            }
        }

        private void btnReLogin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
           
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Close();
        }

        private void barAbout_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //FrmAbout about = new FrmAbout();
            //about.ShowDialog();
        }

        private void barExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (ExMessageBox.Confirm("提示信息：确定要退出吗？", AppSetter.SoftName) == DialogResult.No)
                return;
            this.Close();
        }

        private void barInitialization_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
             
        }

        private void barMenuManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ExtractForm("FrmMenu", "GPM");
        }

        private void barReLogin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            AppSetter.SetValue("AutoLogin", "");
            FrmLogin login = new FrmLogin();
            login.ShowDialog();
        }

        private void barItemMonitor_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LoadMonitor();
        }

        private void LoadMonitor()
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == "FrmLFMonitor")
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }
            FrmLFMonitor form = new FrmLFMonitor();
            form.MdiParent = this;
            form.Show();
        }

        private void barItemSteelPlan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == "FrmSteelPlan")
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }
            FrmSteelPlan form = new FrmSteelPlan();
            form.MdiParent = this;
            form.Show();
        }

        private void barHeatHistory_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == "FrmHeatHistory")
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }
            FrmHeatHistory form = new FrmHeatHistory();
            form.MdiParent = this;
            form.Show();
        }

        private void barItemSteelSample_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == "FrmSteelSample")
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }
            FrmSteelSample form = new FrmSteelSample();
            form.MdiParent = this;
            form.Show();
        }

        private void barItemMaterialConsume_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == "FrmMaterialConsume")
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }
            FrmMaterialConsume form = new FrmMaterialConsume();
            form.MdiParent = this;
            form.Show();
        }

        private void barItemUserInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == "FrmUserInfo")
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }
            FrmUserInfo form = new FrmUserInfo();
            form.MdiParent = this;
            form.Show();
        }

        private void barPlantGraph_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == "FrmPlantGraph")
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }
            FrmPlantGraph form = new FrmPlantGraph();
            form.MdiParent = this;
            form.Show();
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (BaseDocument document in tabbedView1.Documents)
            {
                if (document.Form.Name == "FrmLog")
                {
                    tabbedView1.Controller.Activate(document);
                    return;
                }
            }
            FrmLog form = new FrmLog();
            form.MdiParent = this;
            form.Show();
        }
    }
}